home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 5
/
The 640 Meg Shareware Studio CD-ROM Volume V (Data Express)(1994).ISO
/
amiga
/
tempdemo.lha
/
ProgrammersInfo
/
DSKEL-BAL.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-22
|
10KB
|
399 lines
// SKEL-BAL v1.0
// (BBS ADD/LIST DOOR)
//**********************
//***** Includes *****
//**********************
#include <proto/all.h>
#include <stdio.h>
#include <string.h>
#include <tempest/headers.h>
//********************************
//***** Structures/Defines *****
//********************************
struct MyMessage
{
struct Message Msg;
struct User User;
char text[255];
char text1[255];
int car,Value,Data;
long LongValue;
int IntValue;
};
struct BBSLIST
{
char Name[21],
Number[21],
Location[21],
Sysop[21],
Groups[21],
Support[21],
Nodes[3],
Megs[5],
Baud[6];
};
struct BBSLIST BL;
struct User User;
struct MsgPort *MyPort = NULL;
struct MyMessage *msg;
#define DROP if(EXIT_FLAG) CloseStuff();
void CloseStuff();
void input(char mstring[],int len);
void LineInput(char ostring[],char mstring[],int len);
int DOORIO();
int EXIT_FLAG, DOOR_DATA, DOOR_CAR, DOOR_VALUE, DOOR_VALUE1 = 0,first = 0;
char DOOR_MSG [255],DOOR_MSG1[255],MyName[255],st[100];
char string1[255],string2[255];
//*****************************
//***** PL (Print Line) *****
//*****************************
void pl(fmt,a1,a2,a3)
char *fmt;
{
char s[255];
sprintf(s,fmt,a1,a2,a3);
DOOR_DATA=1; strcpy(DOOR_MSG,s); DOORIO();
}
//******************
//***** Main *****
//******************
void main(int argc,char *argv[])
{
int Test = 1;
if(!DoorStart(argv[1])) { puts("Tempest Door!\n"); exit(0); }
while(Test)
{
pl("\f
[
DSKEL-BAL v0.4
]
BBS Add/List Door By The SkeletoN
[
07-20-93
]\r\n");
pl("
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n");
pl("[
A
] --
Add a number to database.\r\n");
pl("
[
D
] --
Delete a number from database.\r\n");
pl("
[
E
] --
Edit a number in database.\r\n");
pl("
[
L
] --
List Numbers in the database.\r\n");
pl("
[
S
] --
Search for a number in database.\r\n");
pl("
[
Q
] --
Quit back to the BBS.\r\n\r\n");
pl("
Select
[
A,D,E,L,S,Q
] :
");
input(string1,1);
DROP;
if((string1[0] == 'q') || (string1[0] == 'Q')) Test = 0;
if((string1[0] == 'a') || (string1[0] == 'A')) New();
if((string1[0] == 'l') || (string1[0] == 'L')) List();
if((string1[0] == 'e') || (string1[0] == 'E')) Edit();
}
CloseStuff();
}
//*************************
//***** List Entrys *****
//*************************
List()
{
int fd,stat,lines;
lines=0;
fd=Open("DOORS:DSKEL-BAL.Data",MODE_OLDFILE);
if(fd==0) { pl("Error reading Doors:DSKEL-BAL.Data\n\r"); return(0); }
pl("\f");
ReadRecord:
stat=Read(fd,(char *)&BL,sizeof(struct BBSLIST));
if(stat<=0)
{
pl("
Hit any key:");
hotkey(string1);
Close(fd);
return(0);
}
pl("
[
Name
]
%-20s
[
%s
Nodes
] [
Sysop
]
%-20s\r\n",
BL.Name,BL.Nodes,BL.Sysop);
pl("
[
Phone
]
%-20s
[
%4s
Megs
] [
Groups
]
%-20s\r\n",
BL.Number,BL.Megs,BL.Groups);
pl("
[
Located
]
%-20s
[
%5s
Baud
] [
Support
]
%-20s\r\n\r\n",
BL.Location,BL.Baud,BL.Support);
lines+=4;
if(lines+4>User.Length)
{
pl("
Hit any key:");
hotkey(string1);
lines=0;
pl("\r\n\r\n");
}
goto ReadRecord;
}
//***************************
//***** Add New Entry *****
//***************************
New()
{
int fd;
pl("\f
[--------------------]
\r\n");
pl(" BBS Name: ");
input(BL.Name,20);
DROP;
pl("\r\n
[--------------------]
\r\n");
pl(" Phone Number: ");
input(BL.Number,20);
DROP;
pl("\r\n
[--------------------]
\r\n");
pl(" Groups: ");
input(BL.Groups,20);
DROP;
pl("\r\n
[--------------------]
\r\n");
pl(" Location: ");
input(BL.Location,20);
DROP;
pl("\r\n
[--------------------]
\r\n");
pl(" Sysop: ");
input(BL.Sysop,20);
DROP;
pl("\r\n
[--------------------]
\r\n");
pl(" Formats Supported: ");
input(BL.Support,20);
DROP;
pl("\r\n
[-]
\r\n");
pl(" # Nodes: ");
input(BL.Nodes,1);
DROP;
pl("\r\n
[----]
\r\n");
pl(" Megs of Storage: ");
input(BL.Megs,4);
DROP;
pl("\r\n
[-----]
\r\n");
pl(" Max Buad Rate: ");
input(BL.Baud,5);
DROP;
pl("\r\n
Save to database
[
y/n
]
");
input(string1,1);
DROP;
if((string1[0] =='n') || (string1[0] == 'N')) return(0);
//***********************************
//***** Write DSKEL-BAL.Data ******
//***********************************
fd=Open("DOORS:DSKEL-BAL.Data",MODE_OLDFILE);
if(fd==0)
{
fd=Open("DOORS:DSKEL-BAL.Data",MODE_NEWFILE);
if(fd==0)
{
pl("Error writing Doors:DSKEL-BAL.Data!\r\n");
CloseStuff();
}
}
else
Seek(fd,0,OFFSET_END);
Write(fd,(char *)&BL ,sizeof(struct BBSLIST));
Close(fd);
return(0);
}
//*************************
//***** Edit Entrys *****
//*************************
Edit()
{
char string[255];
int fd,Slot;
long Position;
pl("Edit which Entry?: ");
input(string,3);
DROP;
Slot = atoi(string);
fd=Open("DOORS:DSKEL-BAL.Data",MODE_OLDFILE);
if(fd==0)
{
pl("Error reading Doors:DSKEL-BAL.Data\n\r"); return(0);
}
Slot--;
Position = Slot * sizeof(struct BBSLIST);
Seek(fd,Position,0);
Read(fd,(char *)&BL,sizeof(struct BBSLIST));
Close(fd);
pl("\f
[--------------------]
\r\n");
pl(" BBS Name: ");
LineInput(BL.Name,string,20);
DROP;
strcpy(BL.Name,string);
pl("\r\n
[--------------------]
\r\n");
pl(" Phone Number: ");
LineInput(BL.Number,string,20);
DROP;
strcpy(BL.Number,string);
pl("\r\n
[--------------------]
\r\n");
pl(" Groups: ");
LineInput(BL.Groups,string,20);
DROP;
strcpy(BL.Groups,string);
pl("\r\n
[--------------------]
\r\n");
pl(" Location: ");
LineInput(BL.Location,string,20);
DROP;
strcpy(BL.Location,string);
pl("\r\n
[--------------------]
\r\n");
pl(" Sysop: ");
LineInput(BL.Sysop,string,20);
DROP;
strcpy(BL.Sysop,string);
pl("\r\n
[--------------------]
\r\n");
pl(" Formats Supported: ");
LineInput(BL.Support,string,20);
DROP;
strcpy(BL.Support,string);
pl("\r\n
[-]
\r\n");
pl(" # Nodes: ");
LineInput(BL.Nodes,string,1);
DROP;
strcpy(BL.Nodes,string);
pl("\r\n
[----]
\r\n");
pl(" Megs of Storage: ");
LineInput(BL.Megs,string,4);
DROP;
strcpy(BL.Megs,string);
pl("\r\n
[-----]
\r\n");
pl(" Max Buad Rate: ");
LineInput(BL.Baud,string,5);
DROP;
strcpy(BL.Baud,string);
pl("\r\n
Save changes to database
[
y/n
]
");
input(string1,1);
DROP;
if((string1[0] =='n') || (string1[0] == 'N')) return(0);
//***********************************
//***** Write DSKEL-BAL.Data ******
//***********************************
fd=Open("DOORS:DSKEL-BAL.Data",MODE_OLDFILE);
if(fd==0)
pl("Error writing Doors:DSKEL-BAL.Data!\r\n");
else
Seek(fd,Position,0);
Write(fd,(char *)&BL ,sizeof(struct BBSLIST));
Close(fd);
return(0);
}
//*************************
//***** Close Stuff *****
//*************************
void CloseStuff()
{ DOOR_DATA=99; strcpy(DOOR_MSG,'\0'); DOORIO();
while(msg=(struct MyMessage *)GetMsg(MyPort)) ReplyMsg((struct Message *)msg);
if(MyPort) DeletePort(MyPort);
exit(0); }
//********************
//***** DoorIO *****
//********************
int DOORIO()
{
struct MsgPort *HisPort;
struct MyMessage message;
int UPDATE;
if(EXIT_FLAG) return 0;
UPDATE=0;
HisPort = FindPort(st);
if(HisPort!=NULL)
{
message.Msg.mn_Node.ln_Type = NT_MESSAGE;
message.Msg.mn_Length = sizeof(message);
message.Msg.mn_ReplyPort = MyPort;
if(first)CopyMem(&User,&message.User,sizeof(struct User));
message.car = 0;
message.Data = DOOR_DATA;
message.Value = DOOR_VALUE;
message.IntValue = DOOR_VALUE1;
strcpy(message.text,DOOR_MSG);
strcpy(message.text1,DOOR_MSG1);
PutMsg((struct MsgPort *)HisPort,(struct Message *)&message);
Wait(1 << MyPort->mp_SigBit);
GetMsg(MyPort);
DOOR_DATA = message.Data;
DOOR_VALUE = message.Value;
DOOR_VALUE1 = message.IntValue;
strcpy(DOOR_MSG,message.text);
strcpy(DOOR_MSG1,message.text1);
CopyMem(&message.User,&User,sizeof(struct User));
first=1;
UPDATE=0;
if(message.car) EXIT_FLAG=1;
}
return 0;
}
//************************
//***** Door Start *****
//************************
DoorStart(char node[])
{
struct MsgPort *HisPort;
EXIT_FLAG = 0;
sprintf(st,"%s:TEMPEST_DOOR",node);
HisPort = FindPort(st);
if(HisPort==NULL) return (FALSE);
sprintf(MyName,"%s:DOOR_PORT",node);
MyPort = CreatePort(MyName,0L);
if(MyPort==NULL)
{
puts("Cant open port");
return(int)FALSE;
}
DOORIO();
return (int)TRUE;
}
//*********************
//***** Hot Key *****
//*********************
int hotkey(char character[])
{ strcpy(DOOR_MSG,'\0'); DOOR_DATA=20; DOORIO(); strcpy(character,DOOR_MSG);
return((int)character[0]); }
//*******************
//***** Input *****
//*******************
void input(char mstring[],int len)
{ DOOR_DATA=40; DOOR_VALUE=len; strcpy(DOOR_MSG,mstring); DOORIO();
strcpy(mstring,DOOR_MSG); strcpy(DOOR_MSG,'\0'); strcpy(DOOR_MSG1,'\0'); }
//************************
//***** Line Input *****
//************************
void LineInput(char ostring[],char mstring[],int len)
{ DOOR_DATA=41; DOOR_VALUE=len; strcpy(DOOR_MSG,mstring); strcpy(DOOR_MSG1,ostring);
DOORIO(); strcpy(mstring,DOOR_MSG); strcpy(DOOR_MSG,'\0'); strcpy(DOOR_MSG1,'\0'); }